<template>
	<view class="page-box">
		<!-- 否 持有资格证 -->
		<view v-if="pageType == 0">
			<uni-section title="请输入签约经纪人的邀请码" type="line"></uni-section>
			<view class="form-box">
				<view>
					<view>邀请码</view>
					<input type="text" placeholder="请输入邀请码" placeholder-class="placeholder" v-model="userInfo.invitationCode">
				</view>
			</view>
			<!-- 1签约申请 -->
			<view class="big-btn" @click="nextPage(1)">下一步</view>
		</view>
		<!-- 是 持有资格证-->
		<view v-else>
			<uni-section title="请输入您就职的经纪公司" type="line"></uni-section>
			<view class="form-box">
				<view>
					<view>公司名称</view>
					<input type="text" placeholder="请输入公司名称" v-model="userInfo.company">
				</view>
			</view>
			<!-- 2成功 3失败 -->
			<view class="big-btn" @click="nextPage(2)">下一步</view>
		</view>
	</view>
</template>

<script>
	import Vue from 'vue'
	import uniSection from '@/components/uni-section/uni-section.vue'
	import store from '@/store/store.vue'
	
	export default {
		onLoad(option) {
			// 0否 1是
			this.userInfo = JSON.parse(decodeURIComponent(option.param))
			this.pageType = parseInt(option.chooseType)
		},
		components: {
			uniSection
		},
		data() {
			return {
				pageType: 0, // 0否 1是
				userInfo:{
					openId:'',
					invitationCode:'',
					company:''
				}
			}
		},		
		methods: {
			nextPage(status){
				let _this = this
				_this.userInfo.openId = getApp().globalData.open_id
				_this.userInfo.pageType = _this.pageType

				uni.request({
				    url: store.url + '/user/submit_application',
					method: 'POST',
				    data: JSON.stringify(_this.userInfo),
				    header: {
						"content-type": "application/json;charset=utf-8"						
				    },
				    success: (res) => {		
						console.log(res)
						if(res.data.status == 'success'){
							switch(res.data.message){
								case 'committed':
									Vue.prototype.turnPage('authentication/state', 1)	
								break;
								case 'ok':
									Vue.prototype.turnPage('authentication/state', 2)	
								break;
								case 'fail':
									Vue.prototype.turnPage('authentication/state', 3)	
								break;							
								case 'not_exist':		
									uni.showModal({
										title: '提示',
										content: '邀请人不存在'
									});
								break;
							}
						}else{
							uni.showModal({
								title: '提示',
								content: '失败: ' + res.data.message
							});																			
						}																	      
				    },
					fail: (res)=>{
						uni.showModal({
						    title: '提示',
						    content: '访问服务器失败: ' + JSON.stringify(res)
						});						
					}
				});														
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page-box {
		padding-bottom: 88rpx;
		box-sizing: border-box;
		
		/deep/ .uni-section {			
			background: #FFF;
			margin: 5vw;
		}
		
		/deep/ .line {
			background-color: #f13b32;
		}
	}
	
	.form-box {
		margin: 5vw;
		padding-left: 40rpx;
		box-sizing: border-box;
		background: #FFF;
		
		> view {
			display: flex;
			padding-right: 20rpx;
			box-sizing: border-box;
			border-bottom: 1px solid #e5e5e5;
			box-sizing: border-box;
			justify-content: space-between;
			align-items: center;
			font-size: 24rpx;
			
			&:last-of-type {
				border-bottom: none;
			}
			
			view {
				width: 140rpx;
				line-height: 80rpx;
				font-size: 24rpx;
			}
			
			input {
				padding: 20rpx 40rpx 20rpx 0;
				box-sizing: border-box;
				flex: 1;
				height: 80rpx;
				line-height: 40rpx;
			}
			
			/deep/ .placeholder {
			    /* placeholder颜色 */
			    color: #ccc;
			    /* placeholder字体大小 */
			    font-size: 14px;
			}
		}
	}
	
	.big-btn {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		line-height: 88rpx;
		text-align: center;
		color: #FFF;
		background: #f13b32;
	}
</style>
